package com.cqtczh.qhd.driver.acticity.carteam;

import httptools.HttpJsonTool;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javabeen.CarTeamIdBeen;
import javabeen.CompleteCarTeamInfoBeen;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.reflect.TypeToken;
import com.cqtczh.qhd.driver.AppContent;
import com.cqtczh.qhd.driver.R;
import com.cqtczh.qhd.driver.acticity.base.BaseActivity;
import com.cqtczh.qhd.driver.api.GagApi;
import com.cqtczh.qhd.driver.model.CarTeam;

public class Car_Team_Info extends BaseActivity {
	private TextView title;
	private AppContent app;
	private  List<CompleteCarTeamInfoBeen> CompleteCarTeamInfoBeen;
	private String CompleteTeamid;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_car_team_info);
		title = (TextView) findViewById(R.id.head_title);
		title.setVisibility(View.VISIBLE);
		title.setText("公司车队信息");
		Ini();
	}

	private void Ini() {
		Intent intent = getIntent();
		ImageView imageView=(ImageView) findViewById(R.id.head_left);
		imageView.setVisibility(View.VISIBLE);
		imageView.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Car_Team_Info.this.finish();
			}
		});
		CompleteTeamid=intent.getStringExtra("CompleteCarTeamInfo");
		app=(AppContent) getApplication();
		Inis();
	}
	
	private void Inis() {
		HttpJsonTool httpJsonTool=new HttpJsonTool(this);
		HashMap< String, String> data=new HashMap<String, String>();
	 new ArrayList<CompleteCarTeamInfo>();
		
		data.put("orgid", CompleteTeamid);
		httpJsonTool.SetOnLister(new Handler(){
			
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				super.handleMessage(msg);
				if (msg.what==1) {
					CompleteCarTeamInfoBeen=(List<CompleteCarTeamInfoBeen>) msg.obj;
					if (CompleteCarTeamInfoBeen.size()>0) {
						IniUI();
					}
				}else {
					Toast.makeText(Car_Team_Info.this, (String)msg.obj, Toast.LENGTH_LONG).show();
				}
			}
			
		});
		Type type=new TypeToken<List<CompleteCarTeamInfoBeen>>(){}.getType();
		httpJsonTool.StartWork(data, 
				//"http://192.168.1.111:8080/cqtczh/fleets/tcompanymotorcadeorg/getcarteam.do", 
				GagApi.GET_PUSH_COMPLETE_CAR_TEAM_INFO,
				type, null);
		
	}
	
	private void IniUI(){
		TextView textView1=(TextView) findViewById(R.id.ctextVew1);
		TextView textView2=(TextView) findViewById(R.id.ctextVew3);
		TextView textView3=(TextView) findViewById(R.id.ctextVew4);
		TextView textView4=(TextView) findViewById(R.id.ctextVew2);
		textView1.setText("公司名字："+CompleteCarTeamInfoBeen.get(0).getCompanyname());
		textView2.setText("公司车队长名字："+CompleteCarTeamInfoBeen.get(0).getCarownername());
		textView3.setText("公司车队长电话："+CompleteCarTeamInfoBeen.get(0).getPhone());
		textView4.setText("车队名字："+CompleteCarTeamInfoBeen.get(0).getOrgname());
		//因为是推送来的信息查看所以
		Button chek=(Button) findViewById(R.id.chek);
		chek.setVisibility(View.GONE);
		Button agree=(Button) findViewById(R.id.arrge);
		agree.setVisibility(View.VISIBLE);
		agree.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				UpDataDrevier("yes");
			}
		});
		Button reg=(Button) findViewById(R.id.reg);
		reg.setVisibility(View.VISIBLE);
		reg.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				UpDataDrevier("no");
			}
		});
	}
	private void UpDataDrevier(String str){
		showLoadingDialog("系统操作中");
		HttpJsonTool httpJsonTool=new HttpJsonTool(this);
		HashMap< String, String> data=new HashMap<String, String>();
		data.put("companyid", CompleteCarTeamInfoBeen.get(0).getCompanyid()+"");
		data.put("orgid", CompleteCarTeamInfoBeen.get(0).getOrgid()+"");
		data.put("userId", app.userId);
		data.put("state", str);
		httpJsonTool.SetOnLister(new Handler(){
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				dismissLoadingDialog();
				super.handleMessage(msg);
				if (msg.what==1) {
					Toast.makeText(Car_Team_Info.this, "加入成功,您可以点击公司车队查看自己的公司车队", Toast.LENGTH_LONG).show();
					Car_Team_Info.this.finish();
				}else {
					Toast.makeText(Car_Team_Info.this, (String)msg.obj, Toast.LENGTH_LONG).show();
				}
			}
		});
		httpJsonTool.StartWork(data, GagApi.DRIVER_AGREE_OR_NO, null, null);
	}
	
	
}
